package cn.com.infcn.spider.io.input.impl;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.nlpcn.commons.lang.util.IOUtil;
import org.nlpcn.commons.lang.util.StringUtil;

import com.alibaba.fastjson.JSONObject;

import cn.com.infcn.spider.io.input.Input;

public class fileInput implements Input {

	private List<Object> lists = null;

	public fileInput(JSONObject job, String jobName) throws FileNotFoundException, UnsupportedEncodingException, IOException {

		String charEncoding = "utf-8";

		if (job.containsKey("charEncoding")) {
			charEncoding = job.getString("charEncoding");
		}

		lists = new ArrayList<>();

		List<String> readFile2List = IOUtil.readFile2List(job.getString("path"), charEncoding);

		for (String string : readFile2List) {
			if (StringUtil.isBlank(string)) {
				continue;
			}
			lists.add(JSONObject.parseObject(string));
		}
	}

	@Override
	public List<Object> all() {
		return lists;
	}
}
